package com.leetcode.algorithm.y22.m07;

/**
 * 242. 有效的字母异位词
 * 
 * https://leetcode.cn/problems/valid-anagram/
 * 
 * @author jie.deng
 *
 */
public class Question0242Solution01 {

	public boolean isAnagram(String s, String t) {
		if (s.length() != t.length()) {
			return false;
		}
		if (s.equals(t)) {
			return true;
		}
		int[] cntArrS = new int[26];
		for (int i = 0; i < s.length(); i++) {
			cntArrS[s.charAt(i) - 'a']++;
		}
		int[] cntArrT = new int[26];
		for (int i = 0; i < t.length(); i++) {
			cntArrT[t.charAt(i) - 'a']++;
		}
		for (int i = 0; i < 26; i++) {
			if (cntArrS[i] != cntArrT[i]) {
				return false;
			}
		}
		return true;
	}

}
